/*
 * SCS.h
 * 日期: 2022.3.29
 * 作者: 
 */

#ifndef _SCS_H
#define _SCS_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

int genWrite(uint8_t ID, uint8_t MemAddr, uint8_t *nDat, uint8_t nLen);//普通写指令
int regWrite(uint8_t ID, uint8_t MemAddr, uint8_t *nDat, uint8_t nLen);//异步写指令
int regAction(uint8_t ID);//异步写执行行
void syncWrite(uint8_t ID[], uint8_t IDN, uint8_t MemAddr, uint8_t *nDat, uint8_t nLen);//同步写指令
int writeByte(uint8_t ID, uint8_t MemAddr, uint8_t bDat);//写1个字节
int writeWord(uint8_t ID, uint8_t MemAddr, uint16_t wDat);//写2个字节
int Read(uint8_t ID, uint8_t MemAddr, uint8_t *nData, uint8_t nLen);//读指令
int readByte(uint8_t ID, uint8_t MemAddr);//读1个字节
int readWord(uint8_t ID, uint8_t MemAddr);//读2个字节
int Ping(uint8_t ID);//Ping指令
int syncReadPacketTx(uint8_t ID[], uint8_t IDN, uint8_t MemAddr, uint8_t nLen);//同步读指令包发送
int syncReadPacketRx(uint8_t ID, uint8_t *nDat);//同步读返回包解码，成功返回内存字节数，失败返回0
int syncReadRxPacketToByte(void);//解码一个字节
int syncReadRxPacketToWrod(uint8_t negBit);//解码两个字节，negBit为方向为，negBit=0表示无方向
void syncReadBegin(uint8_t IDN, uint8_t rxLen, uint32_t TimeOut);//同步读开始
void syncReadEnd(void);//同步读结束
void writeBuf(uint8_t ID, uint8_t MemAddr, uint8_t *nDat, uint8_t nLen, uint8_t Fun);
void Host2SCS(uint8_t *DataL, uint8_t* DataH, int Data);//1个16位数拆分为2个8位数
int SCS2Host(uint8_t DataL, uint8_t DataH);//2个8位数组合为1个16位数
int Ack(uint8_t ID);//应答
int checkHead(void);//帧头检测

#ifdef __cplusplus
}
#endif

#endif
